package com.tao.erp.goods.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tao.erp.goods.pojo.Goods;
import com.tao.erp.goods.pojo.GoodsType;
import com.tao.erp.goods.service.GoodsService;

@Controller
@RequestMapping("/goods")
public class GoodsAction {
	
	@Autowired
	private GoodsService goodsService;
	
	/**
	 * 异步加载Goods集合
	 * @param goods
	 * @return
	 */
	@RequestMapping("/selectGoodsList.action")
	@ResponseBody
	public List<Goods> selectGoodsList(Goods goods,GoodsType goodsType){
		goods.setGoodsType(goodsType);
		List<Goods> list = goodsService.selectGoodsList(goods);
		return list;
	}

	/**
	 * 通过id删除Goods
	 * @param uuid
	 * @return
	 */
	@RequestMapping("/deleteGoodsById.action")
	public String deleteGoodsById(String uuid){
		int i = goodsService.deleteGoodsById(Integer.parseInt(uuid));
		return "/jsp/goods/goods.jsp";
	}
	
	/**
	 * 通过id查询Goods
	 * @param uuid
	 * @param model
	 * @return
	 */
	@RequestMapping("/selectGoodsById.action")
	public String selectGoodsById(String uuid,Model model){
		Goods goods = goodsService.selectGoodsById(Integer.parseInt(uuid));
		model.addAttribute("goods", goods);
		return "/jsp/goods/goodsupdate.jsp";
	}
	/**
	 * 添加Goods
	 * @param goods
	 * @return
	 */
	@RequestMapping("/insertGoods.action")
	public String insertGoods(Goods goods){
		int i = goodsService.insertGoods(goods);
		return "/jsp/goods/goods.jsp";
	}
	/**
	 * 通过id修改Goods
	 * @param goods
	 * @return
	 */
	@RequestMapping("/updateGoods.action")
	public String updateGoods(Goods goods){
		int i = goodsService.updateGoods(goods);
		System.out.println(i);
		return "/jsp/goods/goods.jsp";
	}
}
